package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KActivityPurchase;
import com.ruoyi.qsng.service.IKActivityPurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动报名Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@Api(tags = "pc--活动报名Controller")
@RestController
@RequestMapping("/qsng/activityPurchase")
public class KActivityPurchaseController extends BaseController {
    @Autowired
    private IKActivityPurchaseService kActivityPurchaseService;

    /**
     * 查询活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:activityPurchase:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询活动报名列表")
    public TableDataInfo list(KActivityPurchase kActivityPurchase) {
        startPage();
        List<KActivityPurchase> list = kActivityPurchaseService.selectKActivityPurchaseList(kActivityPurchase);
        return getDataTable(list);
    }

    /**
     * 导出活动报名列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:activityPurchase:export')")
    @Log(title = "活动报名", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出活动报名列表")
    public void export(HttpServletResponse response, KActivityPurchase kActivityPurchase) {
        List<KActivityPurchase> list = kActivityPurchaseService.selectKActivityPurchaseList(kActivityPurchase);
        ExcelUtil<KActivityPurchase> util = new ExcelUtil<KActivityPurchase>(KActivityPurchase.class);
        util.exportExcel(response, list, "活动报名数据");
    }

    /**
     * 获取活动报名详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:activityPurchase:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取活动报名详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kActivityPurchaseService.selectKActivityPurchaseById(id));
    }

    /**
     * 新增活动报名
     */
    @PreAuthorize("@ss.hasPermi('qsng:activityPurchase:add')")
    @Log(title = "活动报名", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增活动报名")
    public AjaxResult add(@RequestBody KActivityPurchase kActivityPurchase) {
        return toAjax(kActivityPurchaseService.insertKActivityPurchase(kActivityPurchase));
    }

    /**
     * 修改活动报名
     */
    @PreAuthorize("@ss.hasPermi('qsng:activityPurchase:edit')")
    @Log(title = "活动报名", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改活动报名")
    public AjaxResult edit(@RequestBody KActivityPurchase kActivityPurchase) {
        return toAjax(kActivityPurchaseService.updateKActivityPurchase(kActivityPurchase));
    }

    /**
     * 删除活动报名
     */
    @PreAuthorize("@ss.hasPermi('qsng:activityPurchase:remove')")
    @Log(title = "活动报名", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除活动报名")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kActivityPurchaseService.deleteKActivityPurchaseByIds(ids));
    }
}
